//
//  ViewController.m
//  多环境变量demo
//
//  Created by 周焕强 on 2017/3/22.
//  Copyright © 2017年 zhq. All rights reserved.
//

#import "ViewController.h"
#import "NSString+AES256.h"
#import "UIView+Toast.h"

@interface ViewController ()

@property(strong,nonatomic) UITextField * textField;
@property(strong,nonatomic) UILabel * lable;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 100, kScreenWidth - 20, 40)];
    self.textField.layer.borderColor = [[UIColor grayColor] CGColor];
    self.textField.textAlignment = NSTextAlignmentCenter;
    self.textField.layer.borderWidth = 2;
    self.textField.placeholder = @"请输入手机号或者加密后的值";
    
    
    [self.view addSubview:self.textField];
    
    UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake(100, 200, 200, 40)];
    [btn setTitle:@"转换" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(convert) forControlEvents:UIControlEventTouchUpInside];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.view addSubview:btn];
    
    self.lable = [[UILabel alloc] initWithFrame:CGRectMake(10, 300, kScreenWidth - 20, 40)];
    self.lable.layer.borderColor = [[UIColor greenColor] CGColor];
    self.lable.backgroundColor = [UIColor greenColor] ;
    self.lable.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:self.lable];
    self.lable.userInteractionEnabled = YES;
    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleClickEvent)];
    [tapGesture setNumberOfTapsRequired:2];
    [self.lable addGestureRecognizer:tapGesture];
    
    
    
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

-(void)doubleClickEvent{
    NSString * text = self.lable.text;
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = text;
    [self.view makeToast:@"已经复制到剪贴板"];
}

-(void)convert{
    NSString * text = self.textField.text;
    if (text.length == 11) { //手机号
        NSString * resut = [text aes256_encrypt:@"Key"];
        [self.lable setText:resut];
    }
    
    if (text.length > 20) {
        NSString * resut1 = [text aes256_decrypt:@"Key"];
        [self.lable setText:resut1];
    }
}


/**
 UIPasteboard *pasteboard = [UIPasteboardgeneralPasteboard];

 pasteboard.string = @"你好";
 */



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
